<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="88px">
      <!-- <el-form-item label="线索编号" prop="kznum">
        <el-input v-model="queryParams.kznum" placeholder="请输入线索编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
 
      <el-form-item label="当前跟进人" prop="currentFollowupMan">
        <el-input v-model="queryParams.currentFollowupMan" placeholder="请输入当前跟进人" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->

      <el-form-item label="始发地" prop="originPlace">
        <el-select v-model="queryParams.province" placeholder="请选择省" style=" width:165px;" @change="getQueryCitys"
          clearable>
          <el-option v-for="item in provinces" :key="item.id" :label="item.cityName" :value="item.id"></el-option>
        </el-select>

        <el-select v-model="queryParams.city" placeholder="请选择市" style=" width:165px;margin-left: 17px"
          @change="getQueryregions" clearable>
          <el-option v-for="item in queryCitys" :key="item.id" :label="item.cityName" :value="item.id"></el-option>
        </el-select>

        <el-select v-model="queryParams.region" placeholder="请选择区" style=" width:165px;margin-left: 17px" clearable>
          <el-option v-for="item in queryRegions " :key="item.id" :label="item.cityName" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="目的地" prop="aimPlace">
        <el-select v-model="queryParams.aimProvince" placeholder="请选择省" style=" width:165px" @change="getQueryCitysAim"
          clearable>
          <el-option v-for="item in provinces" :key="item.id" :label="item.cityName" :value="item.id"></el-option>
        </el-select>

        <el-select v-model="queryParams.aimCity" placeholder="请选择市" style=" width:165px;margin-left: 20px"
          @change="getQueryregionsAim" clearable>
          <el-option v-for="item in queryCitysAim" :key="item.id" :label="item.cityName" :value="item.id"></el-option>
        </el-select>

        <el-select v-model="queryParams.aimRegion" placeholder="请选择区" style=" width:165px;margin-left: 20px" clearable>
          <el-option v-for="item in queryRegionsAim " :key="item.id" :label="item.cityName"
            :value="item.id"></el-option>
        </el-select>
      </el-form-item>


      <el-form-item label="状态选择" prop="status">
        <el-select v-model="queryParams.status" placeholder="状态选择" clearable>
          <el-option v-for="item in priceStateOpetions" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>

      <el-form-item label="线索编号" prop="kznum">
        <el-input v-model="queryParams.kznum" placeholder="请输入线索编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="当前跟进人" prop="currentFollowupMan">
        <el-input v-model="queryParams.currentFollowupMan" placeholder="请输入当前跟进人" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="线索时间" prop="startKzTime">
        <el-date-picker clearable v-model="queryParams.startKzTime" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择跟进时间">
        </el-date-picker>
        至
        <el-date-picker clearable v-model="queryParams.endKzTime" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择跟进时间">
        </el-date-picker>
      </el-form-item>

      <!-- <el-form-item label="标签" prop="tags"> 
        <el-input v-model="queryParams.tags" placeholder="请输入标签" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

      <el-tag style="margin-left:10px"> 待报价线索数:{{ statistInfo.unpriceCount }} </el-tag>
      <el-tag style="margin-left:10px"> 报价中线索数:{{ statistInfo.priceingCount }} </el-tag>
      <el-tag style="margin-left:10px"> 已完成线索数:{{ statistInfo.finisthedCount }} </el-tag>

      <!--  <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['system:clue:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['system:clue:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:clue:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
    </el-row>

    <el-table v-loading="loading" :data="clueList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="线索编号" align="center" prop="kznum" />
      <el-table-column label="线索平台" align="center" prop="kzplatform" />
      <!--   <el-table-column label="线索账户" align="center" prop="kzaccount" />
      <el-table-column label="来源页面" align="center" prop="sourceWeb" /> -->
      <el-table-column label="线索昵称" align="center" prop="kzNickname" />
      <el-table-column label="线索电话" align="center" prop="kzphoneNumber" />
      <el-table-column label="车型" align="center" prop="vehicleTypeOne" />
      <el-table-column label="车辆类型" align="center" prop="tags" />
      <el-table-column label="始发地" align="center" prop="originPlaceDetail">
        <template slot-scope="scope">
          <span>{{ (scope.row.provinceString) }}/{{ (scope.row.cityString) }}/{{ (scope.row.regionString) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="目的地" align="center" prop="aimPlaceDetail">

        <template slot-scope="scope">
          <span>{{ (scope.row.aimProvinceString) }}/{{ (scope.row.aimCityString) }}/{{ (scope.row.aimRegionString)
            }}</span>
        </template>
      </el-table-column>
      <el-table-column label="车辆估值" align="center" prop="vehicleEstimationValue" />
      <el-table-column label="报价" align="center" prop="price" />
      <el-table-column label="承运公司" align="center" prop="acceptCompanyStr" />
      <el-table-column label="运费" align="center" prop="transFee" />
      <el-table-column label="标签" align="center" prop="tags" />

      <el-table-column label="报价人" align="center" prop="currentPriceName" />
      <el-table-column label="报价时间" align="center" prop="priceTime" width="180">
      </el-table-column>

      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <span v-if="scope.row.status == 2">待报价</span>
          <span v-if="scope.row.status == 3">报价中</span>
          <span v-if="scope.row.status == 4">已完成</span>
        </template>
      </el-table-column>

      <el-table-column label="线索时间" align="center" prop="followupTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="checkDetail(scope.row)" v-if="scope.row.status > 3">详情</el-button>
          <el-button size="mini" type="text" @click="handleUpdate(scope.row)" v-if="scope.row.status < 4">报价</el-button>
          <!-- <el-button size="mini" type="text" v-if="scope.row.status < 4"
            @click="handlePriceStep(scope.row)"></el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改跟进信息 -->
    <el-dialog :title="title" :visible.sync="openStep" width="500px" append-to-body>
      <el-form ref="stepForm" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="客户电话">
          {{ currentPhone }}
        </el-form-item>
        <el-form-item label="内容记录">
          <el-input v-model="stepForm.content" type="textarea" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitStepForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="title" :visible.sync="openPriceStep" width="500px" append-to-body>
      <el-form ref="stepForm" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="客户电话">
          {{ currentPhone }}
        </el-form-item>
        <el-form-item label="价格">
          <el-input v-model="stepForm.price" type="number" />
        </el-form-item>
        <el-form-item label="内容记录">
          <el-input v-model="stepForm.content" type="textarea" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitPriceStepForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <h3>基本信息</h3>
        <div class="row-between" style="width: 100%;">
          <div style="width: 75%;">
            <el-row>
              <el-col :span="7">
                <el-form-item label="线索编号" prop="kznum">
                  <span>{{ form.kznum }}</span>
                  <!-- <el-input v-model="form.kznum" placeholder="请输入线索编号" maxlength="30" /> -->
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="线索时间" prop="kzplatform">
                  <span>{{ form.createTime }}</span>
                  <!-- <el-input v-model="form.kzplatform" placeholder="请输入线索平台" maxlength="30" /> -->
                </el-form-item>
              </el-col>


              <el-col :span="6">
                <el-form-item label="主结构" prop="kzplatform">
                  <span>运车网</span>
                  <!-- <el-input v-model="form.kzplatform" placeholder="请输入线索平台" maxlength="30" /> -->
                </el-form-item>
              </el-col>


            </el-row>
            <el-row>
              <el-col :span="6">
                <el-form-item label-width="100px" label="报价单编号" prop="kznum">
                  <span>{{ form.priceNum }}</span>
                  <!-- <el-input v-model="form.kznum" placeholder="请输入线索编号" maxlength="30" /> -->
                </el-form-item>
              </el-col>
              <el-col :span="7">
                <el-form-item label="报价单时间" label-width="100px" prop="kzplatform">
                  <span>{{ form.priceTime }}</span>
                  <!-- <el-input v-model="form.kzplatform" placeholder="请输入线索平台" maxlength="30" /> -->
                </el-form-item>
              </el-col>
            </el-row>

            <h3>基本信息</h3>

            <el-row>
              <el-col :span="6">

                <el-form-item label="线索平台" prop="kzplatform">
                  <span>{{ form.kzplatform }}</span>
                  <!-- <el-input v-model="form.kzplatform" placeholder="请输入线索平台" maxlength="30" /> -->
                </el-form-item>
              </el-col>


              <el-col :span="6">
                <el-form-item label="线索账户" prop="kzaccount">
                  <span>{{ form.kzaccount }}</span>
                  <!-- <el-input v-model="form.kzaccount" placeholder="请输入线索账户" /> -->
                </el-form-item>
              </el-col>

              <el-col :span="6">
                <el-form-item label="来源页面" prop="sourceWeb">
                  <span>{{ form.sourceWeb }}</span>
                  <!-- <el-input v-model="form.sourceWeb" placeholder="请输入来源页面" /> -->
                </el-form-item>
              </el-col>
            </el-row>



            <h3>客户信息</h3>
            <el-row>
              <el-col :span="6">
                <el-form-item label="线索昵称" prop="kzNickname">
                  <span>{{ form.kzNickname }}</span>
                  <!-- <el-input v-model="form.kzNickname" placeholder="请输入线索昵称" /> -->
                </el-form-item>
              </el-col>


              <el-col :span="6">
                <el-form-item label="线索电话" prop="kzphoneNumber">
                  <span>{{ form.kzphoneNumber }}</span>
                  <!-- <el-input v-model="form.kzphoneNumber" placeholder="请输入线索电话" /> -->
                </el-form-item>
              </el-col>

              <el-col :span="6">
                <el-form-item label="车型" prop="vehicleTypeOne">
                  <span>{{ form.vehicleTypeOne }}</span>
                  <!-- <el-input v-model="form.vehicleTypeOne" placeholder="请输入车辆类型" /> -->
                </el-form-item>
              </el-col>
            </el-row>



            <h3>标签信息</h3>
            <el-row>
              <el-col :span="14">
                <el-form-item label="标签" prop="tags">
                  {{ form.tags }}
                </el-form-item>
              </el-col>
            </el-row>


            <h3>车辆信息</h3>
            <el-row>
              <el-col :span="6">
                <el-form-item label="标签" prop="vehicleTypeOne">
                  {{ form.vehicleTypeOne }}
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="车辆估值" prop="vehicleEstimationValue">
                  {{ form.vehicleEstimationValue }}
                </el-form-item>
              </el-col>
            </el-row>


            <h3>路线信息</h3>
            <el-row>
              <el-col :span="6">
                <el-form-item label="始发地" prop="originPlace">
                  {{ form.originPlace }}
                </el-form-item>
              </el-col>
              <el-col :span="10">
                <el-form-item label="详细信息" prop="originPlaceDetail">
                  {{ form.originPlaceDetail }}
                </el-form-item>
              </el-col>
            </el-row>


            <el-row>
              <el-col :span="6">
                <el-form-item label="目的地" prop="aimPlace">
                  {{ form.aimPlace }}
                </el-form-item>
              </el-col>
              <el-col :span="10">
                <el-form-item label="详细信息" prop="aimPlaceDetail">
                  {{ form.aimPlaceDetail }}
                </el-form-item>
              </el-col>
            </el-row>
          </div>
          <div style="width: 25%;height: 100%;">
            <el-timeline>
              <el-timeline-item v-for="(activity, index) in form.followList" :key="index"
                :timestamp="activity.createTime + '  ' + activity.stepUserName">
                {{ activity.content }}
              </el-timeline-item>
            </el-timeline>
          </div>
        </div>
        <h3>报价记录</h3>
        <el-table v-loading="loading" :data="form.priceList">
          <el-table-column label="序号" align="center">
            <template slot-scope="scope">
              <span> {{ scope.$index + 1 }}</span>
            </template>
          </el-table-column>
          <el-table-column label="价格" align="center" prop="price" />
          <el-table-column label="联系内容" align="center" prop="content" />
          <el-table-column label="操作人" align="center" prop="stepUserName" />
          <el-table-column label="报价时间" align="center" prop="createTime" />
        </el-table>
        <h3>报价信息</h3>
        <el-row>
          <el-col :span="6">
            <el-form-item label="运费" prop="transFee">
              <el-input v-model="form.transFee" placeholder="请输入运费" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="利润" prop="proft">
              <el-input v-model="form.proft" placeholder="请输入利润" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <!-- <el-form-item label="承运公司" prop="acceptCompany">
                  <el-input v-model="form.acceptCompany" placeholder="请输入车辆估值" />
                </el-form-item> -->
            <el-form-item label="承运公司" prop="acceptCompany">
              <el-select v-model="form.acceptCompany" placeholder="请选择标签" clearable>
                <el-option v-for="item in deptList" :key="item.deptId" :label="item.deptName" :value="item.deptId" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>


      <h3>本次报价</h3>
      <el-form ref="stepForm" :model="form" :rules="rules" label-width="100px">

        <el-row>
          <el-col :span="6">
            <el-form-item label="价格">
              <el-input v-model="stepForm.price" type="number" width="50px" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="内容记录">
          <el-input v-model="stepForm.content" type="textarea" />
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitPriceStepForm(3)">提交本次报价</el-button>
        <el-button type="primary" @click="submitPriceStepForm(4)">完成报价</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="title" :visible.sync="detailOpen" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <h3>基本信息</h3>
        <div class="row-between" style="width: 100%;">
          <div style="width: 75%;">
            <el-row>
              <el-col :span="7">
                <el-form-item label="线索编号" prop="kznum">
                  <span>{{ form.kznum }}</span>
                  <!-- <el-input v-model="form.kznum" placeholder="请输入线索编号" maxlength="30" /> -->
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="线索时间" prop="kzplatform">
                  <span>{{ form.createTime }}</span>
                  <!-- <el-input v-model="form.kzplatform" placeholder="请输入线索平台" maxlength="30" /> -->
                </el-form-item>
              </el-col>


              <el-col :span="6">
                <el-form-item label="主结构" prop="kzplatform">
                  <span>运车网</span>
                  <!-- <el-input v-model="form.kzplatform" placeholder="请输入线索平台" maxlength="30" /> -->
                </el-form-item>
              </el-col>


            </el-row>
            <el-row>
              <el-col :span="6">
                <el-form-item label-width="100px" label="报价单编号" prop="kznum">
                  <span>{{ form.priceNum }}</span>
                  <!-- <el-input v-model="form.kznum" placeholder="请输入线索编号" maxlength="30" /> -->
                </el-form-item>
              </el-col>
              <el-col :span="7">
                <el-form-item label="报价单时间" label-width="100px" prop="kzplatform">
                  <span>{{ form.priceTime }}</span>
                  <!-- <el-input v-model="form.kzplatform" placeholder="请输入线索平台" maxlength="30" /> -->
                </el-form-item>
              </el-col>
            </el-row>

            <h3>基本信息</h3>

            <el-row>
              <el-col :span="6">

                <el-form-item label="线索平台" prop="kzplatform">
                  <span>{{ form.kzplatform }}</span>
                  <!-- <el-input v-model="form.kzplatform" placeholder="请输入线索平台" maxlength="30" /> -->
                </el-form-item>
              </el-col>


              <el-col :span="6">
                <el-form-item label="线索账户" prop="kzaccount">
                  <span>{{ form.kzaccount }}</span>
                  <!-- <el-input v-model="form.kzaccount" placeholder="请输入线索账户" /> -->
                </el-form-item>
              </el-col>

              <el-col :span="6">
                <el-form-item label="来源页面" prop="sourceWeb">
                  <span>{{ form.sourceWeb }}</span>
                  <!-- <el-input v-model="form.sourceWeb" placeholder="请输入来源页面" /> -->
                </el-form-item>
              </el-col>
            </el-row>



            <h3>客户信息</h3>
            <el-row>
              <el-col :span="6">
                <el-form-item label="线索昵称" prop="kzNickname">
                  <span>{{ form.kzNickname }}</span>
                  <!-- <el-input v-model="form.kzNickname" placeholder="请输入线索昵称" /> -->
                </el-form-item>
              </el-col>


              <el-col :span="6">
                <el-form-item label="线索电话" prop="kzphoneNumber">
                  <span>{{ form.kzphoneNumber }}</span>
                  <!-- <el-input v-model="form.kzphoneNumber" placeholder="请输入线索电话" /> -->
                </el-form-item>
              </el-col>

              <el-col :span="6">
                <el-form-item label="车型" prop="vehicleTypeOne">
                  <span>{{ form.vehicleTypeOne }}</span>
                  <!-- <el-input v-model="form.vehicleTypeOne" placeholder="请输入车辆类型" /> -->
                </el-form-item>
              </el-col>
            </el-row>



            <h3>标签信息</h3>
            <el-row>
              <el-col :span="14">
                <el-form-item label="标签" prop="tags">
                  {{ form.tags }}
                </el-form-item>
              </el-col>
            </el-row>


            <h3>车辆信息</h3>
            <el-row>
              <el-col :span="6">
                <el-form-item label="标签" prop="vehicleTypeOne">
                  {{ form.vehicleTypeOne }}
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="车辆估值" prop="vehicleEstimationValue">
                  {{ form.vehicleEstimationValue }}
                </el-form-item>
              </el-col>
            </el-row>


            <h3>路线信息</h3>
            <el-row>
              <el-col :span="6">
                <el-form-item label="始发地" prop="originPlace">
                  {{ form.originPlace }}
                </el-form-item>
              </el-col>
              <el-col :span="10">
                <el-form-item label="详细信息" prop="originPlaceDetail">
                  {{ form.originPlaceDetail }}
                </el-form-item>
              </el-col>
            </el-row>


            <el-row>
              <el-col :span="6">
                <el-form-item label="目的地" prop="aimPlace">
                  {{ form.aimPlace }}
                </el-form-item>
              </el-col>
              <el-col :span="10">
                <el-form-item label="详细信息" prop="aimPlaceDetail">
                  {{ form.aimPlaceDetail }}
                </el-form-item>
              </el-col>
            </el-row>
          </div>
          <div style="width: 25%;height: 100%;">
            <el-timeline>
              <el-timeline-item v-for="(activity, index) in form.followList" :key="index"
                :timestamp="activity.createTime + '  ' + activity.stepUserName">
                {{ activity.content }}
              </el-timeline-item>
            </el-timeline>
          </div>
        </div>
        <h3>报价记录</h3>
        <el-table v-loading="loading" :data="form.priceList">
          <el-table-column label="序号" align="center">
            <template slot-scope="scope">
              <span> {{ scope.$index + 1 }}</span>
            </template>
          </el-table-column>
          <el-table-column label="价格" align="center" prop="price" />
          <el-table-column label="联系内容" align="center" prop="content" />
          <el-table-column label="操作人" align="center" prop="stepUserName" />
          <el-table-column label="报价时间" align="center" prop="createTime" />
        </el-table>
        <h3>报价信息</h3>
        <el-row>
          <el-col :span="6">
            <el-form-item label="运费" prop="transFee">
              <el-input v-model="form.transFee" placeholder="请输入运费" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="利润" prop="proft">
              <el-input v-model="form.proft" placeholder="请输入利润" disabled />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <!-- <el-form-item label="承运公司" prop="acceptCompany">
                  <el-input v-model="form.acceptCompany" placeholder="请输入车辆估值" />
                </el-form-item> -->
            <el-form-item label="承运公司" prop="acceptCompany">
              <el-select v-model="form.acceptCompany" placeholder="请选择标签" disabled>
                <el-option v-for="item in deptList" :key="item.deptId" :label="item.deptName" :value="item.deptId" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { listClue, getClue, delClue, addClue, updateClue, getclueStatistState } from "@/api/crm/clue";

import { listStep, getStep, delStep, addStep, updateStep } from "@/api/crm/step";

import { listDept } from "@/api/system/dept";

import { addPriceStep } from "@/api/crm/pricestep";
import { getlistAllTypes } from "@/api/crm/tag";


import { listChina } from "@/api/crm/china";

export default {
  name: "Clue",
  data() {
    return {
      //时间条
      reverse: true,
      activities: [{
        content: '活动按期开始',
        timestamp: '2018-04-15'
      }, {
        content: '通过审核',
        timestamp: '2018-04-13'
      }, {
        content: '创建成功',
        timestamp: '2018-04-11'
      }],
      priceStateOpetions: [{
        "label": "待报价",
        "value": 2
      }, {
        "label": "报价中",
        "value": 3
      }, {
        "label": "已完成",
        "value": 4
      }],
      // 遮罩层
      loading: true,

      statistInfo: {},
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      clueList: [],
      // 弹出层标题
      title: "",
      provinces: [],
      queryCitys: [],
      queryRegions: [],
      queryCitysAim: [],
      queryRegionsAim: [],
      // 是否显示弹出层
      open: false,
      openStep: false,
      openPriceStep: false,
      detailOpen: false,
      currentPhone: '',
      deptList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        kznum: null,
        kzplatform: null,
        kzaccount: null,
        sourceWeb: null,
        kzNickname: null,
        vehicleEstimationValue: null,
        kzphoneNumber: null,
        vehicleTypeOne: null,
        vehicleTypeTwo: null,
        followupTime: null,
        currentFollowupMan: null,
        status: null,
        acceptCompany: null,
        originPlace: null,
        aimPlace: null,
        transFee: null,
        priceNum: null,
        priceTime: null,
        price: null,
        tags: null,
        province: null,
        city: null,
        region: null,
        aimProvince: null,
        aimCity: null,
        aimRegion: null,
        remarks: null
      },
      // 表单参数
      form: {},
      stepForm: {},
      tagItems: [],
      chinaList: [],
      taglistOptions: {},
      // 表单校验
      rules: {
        acceptCompany: [
          { required: true, message: "请输入承运公司", trigger: "blur" }
        ],
        transFee: [
          { required: true, message: "请输入运费", trigger: "blur" }
        ],
        proft: [
          { required: true, message: "请输入利润", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getlistAllTypes();
    // this.listChina();
    this.getListDept();
    this.getlistChina();
  },
  methods: {

    getlistChina() {
      var queryParams1 = {
        pageNum: 1,
        pageSize: 10000,
      };
      listChina(queryParams1).then(response => {
        this.provinces = response.rows.filter(item => item.depth == 1);
        this.cityslist = response.rows.filter(item => item.depth == 2);
        this.regionslist = response.rows.filter(item => item.depth == 3);
        // this.citys = response.rows.filter(item => item.depth == 2);
        // this.regions = response.rows.filter(item => item.depth == 3);
        //  this.citysAim = this.citys;
        // this.regionsAim = this.regions;
      });
    },
    //////////////////////
    getQueryCitys(value) {
      this.queryCitys = this.cityslist.filter(item => parseInt(item.parentId) == parseInt(value));
      this.queryParams.city = '';
      this.queryParams.region = '';
    },
    getQueryregions(value) {
      this.queryRegions = this.regionslist.filter(item => parseInt(item.parentId) == parseInt(value));
      this.queryParams.region = '';
    },
    getQueryCitysAim(value) {
      this.queryCitysAim = this.cityslist.filter(item => parseInt(item.parentId) == parseInt(value));
      this.queryParams.aimCity = '';
      this.queryParams.aimRegion = '';
    },
    getQueryregionsAim(value) {
      this.queryRegionsAim = this.regionslist.filter(item => parseInt(item.parentId) == parseInt(value));
      this.queryParams.aimRegion = '';
    },

    ////////////////////////
    togetclueStatistState() {
      getclueStatistState().then(response => {
        this.statistInfo = response.data;
      });
    },

    getListDept() {
      this.loading = true;
      listDept(this.queryParams).then(response => {
        response.data.map((item, index) => {
          if (item.ancestors.split(",").length > 2) {
            this.deptList.push(item);
          }
        });
        console.log(this.deptList);

      });
    },



    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      this.queryParams.followType = 1;
      listClue(this.queryParams).then(response => {
        this.clueList = response.rows;
        this.total = response.total;
        this.loading = false;
        this.togetclueStatistState();
      });
    },

    getlistAllTypes() {
      var param1 = {};
      getlistAllTypes(param1).then(response => {
        this.taglistOptions = response.data;
      });
    },


    // listChina() {
    //   var param2 = {
    //     pageNum: 1,
    //     pageSize: 1000
    //   };
    //   listChina(this.param2).then(response => {
    //     this.chinaList = response.rows;
    //     this.total = response.total;
    //     this.loading = false;
    //   });
    // },

    // 取消按钮
    cancel() {
      this.open = false;
      this.openStep = false;
      this.openPriceStep = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        kznum: null,
        kzplatform: null,
        kzaccount: null,
        sourceWeb: null,
        kzNickname: null,
        vehicleEstimationValue: null,
        kzphoneNumber: null,
        vehicleTypeOne: null,
        vehicleTypeTwo: null,
        followupTime: null,
        currentFollowupMan: null,
        status: null,
        acceptCompany: null,
        originPlace: null,
        aimPlace: null,
        transFee: null,
        priceNum: null,
        priceTime: null,
        price: null,
        tags: null,
        createTime: null,
        remarks: null
      };
      this.resetForm("form");
    },

    ///跟进form
    stepFormReset() {
      this.stepForm = {
        clueId: null,
        content: null,
        stepUserName: null,
        stepName: null,
        createTime: null,
        remarks: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if (this.queryParams.startKzTime != undefined) {
        this.queryParams.startKzTime = this.queryParams.startKzTime.substring(0, 10) + " 00:00:00";
      }

      if (this.queryParams.endKzTime != undefined) {
        this.queryParams.endKzTime = this.queryParams.endKzTime.substring(0, 10) + " 23:59:59";
      }
      this.getList();
    },
    resetQuery() {
      this.queryParams = {
        // pageNum: 1,
        // pageSize: 10,
        // kznum: null,
        // kzplatform: null,
        // kzaccount: null,
        // sourceWeb: null,
        // kzNickname: null,
        // vehicleEstimationValue: null,
        // kzphoneNumber: null,
        // vehicleTypeOne: null,
        // vehicleTypeTwo: null,
        // followupTime: null,
        // currentFollowupMan: null,
        // status: null,
        // acceptCompany: null,
        // originPlace: null,
        // aimPlace: null,
        // transFee: null,
        // priceNum: null,
        // priceTime: null,
        // price: null,
        // tags: null,
        province: null,
        city: null,
        region: null,
        aimProvince: null,
        aimCity: null,
        aimRegion: null,
        remarks: null
      }
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      //this.resetQuery();
      this.queryParams = {};
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "修改";
    },

    handleStep(row) {
      this.stepFormReset();
      this.currentPhone = row.kzphoneNumber;
      const id = row.id || this.ids;
      this.openStep = true;
      this.stepForm.clueId = id;
    },


    handlePriceStep(row) {
      this.stepFormReset();
      this.currentPhone = row.kzphoneNumber;
      const id = row.id || this.ids;
      this.openPriceStep = true;
      this.stepForm.clueId = id;
    },

    /** addPriceStep  报价提交按钮 */

    submitPriceStepForm(statuePararm) {
      this.stepForm.clueId = this.form.id;
      this.$refs["stepForm"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            this.stepForm.status = 1;
            addPriceStep(this.stepForm).then(response => {
              this.$modal.msgSuccess("报价成功");
              this.openPriceStep = false;
              // this.getList();
              this.submitForm(statuePararm)
            });
          }

          //同时修改运费等信息
        }
      });
    },

    /** 跟进提交按钮 */
    submitStepForm() {
      this.$refs["stepForm"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            addStep(this.stepForm).then(response => {
              // this.$modal.msgSuccess("修改成功");
              this.openStep = false;
              this.getList();
            });
          } else {
            addStep(this.stepForm).then(response => {
              //this.$modal.msgSuccess("跟进成功");
              this.openStep = false;
              this.getList();
            });
          }
        }
      });
    },
    checkDetail(row) {
      const id = row.id || this.ids
      getClue(id).then(response => {
        this.form = response.data;
        this.form.acceptCompany = parseInt(this.form.acceptCompany);
        this.detailOpen = true;
        this.title = "详情";
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getClue(id).then(response => {
        this.form = response.data;
        this.form.acceptCompany = parseInt(this.form.acceptCompany);
        this.open = true;
        this.title = "修改";
      });
    },
    /** 提交按钮 */
    submitForm(statuePararm) {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.price = null;
          this.form.status = statuePararm;
          if (this.form.id != null) {
            updateClue(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          }

        }
      });
    },

    /** 移交报价 */

    toPrice(row) {
      const id = row.id || this.ids
      this.reset();
      this.form.id = id;
      this.form.status = 2;
      updateClue(this.form).then(response => {
        this.$modal.msgSuccess("移交成功");
        this.open = false;
        this.getList();
      });
    },







    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项？').then(function () {
        return delClue(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/clue/export', {
        ...this.queryParams
      }, `clue_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style lang="scss" scoped>
.row-between {
  display: flex;
  flex-flow: row nowrap;
  justify-content: space-between;
}

::v-deep .el-timeline-item__node {
  background-color: #02A7F0 !important;
}

::v-deep .el-timeline-item__tail {
  position: absolute;
  left: 4px;
  height: 100%;
  border-left: 2px solid #02A7F0;
}
</style>
